package com.test.springboot.springBootUtils.service.shell;

import org.springframework.shell.Availability;
import org.springframework.shell.standard.ShellComponent;
import org.springframework.shell.standard.ShellMethod;

@ShellComponent
public class CollectionCommands {
	private final ConsoleService console;
	private final CrmService crm;
	 CollectionCommands(CrmService crm,ConsoleService console){
		this.crm=crm;
		this.console=console;
	}
	 
	 @ShellMethod("connect to crm")
	 public void connect(String username,String password) {
		 this.crm.Connection(username, password);
		 this.console.write("connected %s", username);
	 }
	 @ShellMethod("disconnect from the crm")
	 public void disconnect() {
		this.crm.disconnect();
	}
	 
	 Availability disconnectAvailability() {
		 return this.crm.isConnected()?Availability.available():Availability.unavailable("you are not connected");
	 }
	 
	 Availability connectAvailability() {
		 return !this.crm.isConnected()?Availability.available():Availability.unavailable("you are already connected");
	 }
	 
	
	

}
